{% extends 'home.html' %}

{% block content %}
    <h1 class="text-center">书籍编辑</h1>
    <form action="{% url 'book_edit' edit_obj.pk %}" method="post">
        {% csrf_token %}
        <p>
            书名:<input type="text" class="form-control" name="title" value="{{ edit_obj.title }}">
        </p>
        <p>
            价格:<input type="text" class="form-control" name="price" value="{{ edit_obj.price }}">
        </p>
        <p>
            出版日期:<input type="date" class="form-control" name="publish_date"
                        value="{{ edit_obj.publish_date | date:'Y-m-d' }}">
        </p>
        <p>
            出版社:
            <select name="publish" id="" class="form-control">
                {% for publish_obj in publish_queryset %}
                    {% if publish_obj.pk == edit_obj.publish.pk %}
                        <option value="{{ publish_obj.pk }}" selected>{{ publish_obj.name }}</option>
                    {% else %}
                        <option value="{{ publish_obj.pk }}">{{ publish_obj.name }}</option>
                    {% endif %}

                {% endfor %}
            </select>
        </p>
        <p>
            作者:
            <select name="authors" id="" class="form-control" multiple>
                {% for author_obj in author_queryset %}
                    {% if author_obj in edit_obj.authors.all %}
                        <option value="{{ author_obj.pk }}" selected>{{ author_obj.name }}</option>
                    {% else %}
                        <option value="{{ author_obj.pk }}">{{ author_obj.name }}</option>
                    {% endif %}

                {% endfor %}

            </select>
        </p>
        <input type="submit" class="btn btn-primary btn-block" value="新增">
    </form>
{% endblock %}